<?php
/**
 * @Copyright Copyright (C) 2010-2012
 * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
 + Created by:          Webit Solution
 * Company:		Webit Solution
 + Contact:		www.webits.asia, developer@webits.asia
 * Created on:	Mar 21, 2012
 ^
 + Project: 		WRecruit
 * File Name:	views/jobseeker/view.html.php
 ^ 
 * Description: HTML view class for jobseeker
 ^ 
 * History:		NONE
 ^ 
 */

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');
jimport('joomla.html.pagination');

class WRecruitViewJobseeker extends JView
{

	function display($tpl = null)
	{
		global $mainframe, $sorton, $sortorder, $option;

		$document	   =& JFactory::getDocument();
		$user	=& JFactory::getUser();
		$uid=$user->id;
		$viewtype = 'html';
		$type = 'offl';
		$option = 'com_wrecruit';
		$userrole = Array();
		$mainframe = &JFactory::getApplication();
		
	    $version = new JVersion;
	    $joomla = $version->getShortVersion();
		$jversion = substr($joomla,0,3);

		$itemid =  JRequest::getVar('Itemid');
		$layout =  JRequest::getVar('layout');

		$model		= &$this->getModel();
		// get configurations
		//$config = Array();
                $session = JFactory::getSession();
                $config = $session->get('jsjobconfig_dft');
				$curuser = $session->get('jsjobcur_usr');
				if($curuser != $uid) unset($config);
				$session->set('jsjobcur_usr', $uid);

		if(isset($config))
				if($config['testing_mode'] == 1)
				unset($config);

                if(!isset($config)){
					$results =  $model->getConfig('');
					if ($results){ //not empty
						foreach ($results as $result){
							$config[$result->configname] = $result->configvalue;
						}
						$result =  $model->getTypeStatus();
						$type .= $result[0];
						$value = $result[1];
						if ($config[$type] != 1) $config[$type] = $value;
							$session->set('jsjobconfig_dft', $config);
					}

                }
				$config['offline'] = 0;
                $needlogin = true;
                switch($layout){
                    case 'controlpanel': if ($config['visitorview_js_controlpanel'] == 1) $needlogin = false; break;
                    case 'packages': if ($config['visitorview_js_packages'] == 1) $needlogin = false; break;
                    case 'package_details': if ($config['visitorview_js_viewpackage'] == 1) $needlogin = false; break;
                    case 'jobcat': if ($config['visitorview_wrecruitcat'] == 1) $needlogin = false; break;
                    case 'browsejobs': if ($config['visitorview_js_listjob'] == 1) $needlogin = false; break;
                    case 'list_jobs_company': if ($config['visitorview_js_listjob'] == 1) $needlogin = false; break;
                    case 'list_subcategoryjobs': if ($config['visitorview_js_listjob'] == 1) $needlogin = false; break;
                    case 'listnewestjobs': if ($config['visitorview_js_newestjobs'] == 1) $needlogin = false; break;
                    case 'jobsearch': if ($config['visitorview_wrecruitsearch'] == 1) $needlogin = false; break;
                    case 'job_searchresults': if ($config['visitorview_wrecruitsearchresult'] == 1) $needlogin = false; break;
                    case 'jobalertsetting': if ($config['overwrite_jobalert_settings'] == 1) $needlogin = false; break;
                    case 'jobalertunsubscribe': if ($config['overwrite_jobalert_settings'] == 1) $needlogin = false; break;
                    case 'company_jobs': if ($config['visitorview_emp_viewcompany'] == 1) $needlogin = false; break;
                    case 'job_apply':
                        if ($config['visitor_can_apply_to_job'] == 1) $needlogin = false;
                        break;
                    case 'formresume': 
                            if ($config['visitor_can_apply_to_job'] == 1){
                                $session = JFactory::getSession();
                                $visitor = $session->get('jsjob_jobapply');
                                if ($visitor['visitor'] == 1)$needlogin = false;
                            }
                            break;
                    case 'business_version': $needlogin = false; break;
                    default : $needlogin = true; break;
                }
				
				if ($user->guest) { // redirect user if not login
					if($needlogin){
								$_SESSION['wrecruit_option'] = 'com_wrecruit';
								$_SESSION['wrecruit_view'] = 'jobseeker';
								$_SESSION['wrecruit_red_layout'] = $layout;
								$cmpurl="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
								$_SESSION['wrecruit_comp_url'] = $cmpurl;

								$msg = JText::_('JS_LOGIN_DESCRIPTION');
								$redirectUrl = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=successfullogin';
								$redirectUrl = '&amp;return='.base64_encode($redirectUrl);
								//$finalUrl = 'index.php?option=com_user&view=login'. $redirectUrl;
								if($config['login_redirect']){
									$finalUrl = $config['login_redirect']. $redirectUrl;
									
								}else{
									if($jversion == '1.5'){
										$finalUrl = 'index.php?option=com_user&view=login'. $redirectUrl;
									}else{
										$finalUrl = 'index.php?option=com_users&view=login'. $redirectUrl;
									}
									
								}
								$mainframe->redirect($finalUrl,$msg);
					}			
				} 
		
		if($option == '')
			$option='com_wrecruit';
		$limit		= $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
		$limitstart	= $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
		$limitstart =  JRequest::getVar('limitstart',0);

		if (isset($_SESSION['wrecruit_layout'])){
			if ($layout != $_SESSION['wrecruit_layout']) {
				$_SESSION['wrecruit_layout'] = $layout;
				$limitstart = 0;
			}
		}else $_SESSION['wrecruit_layout'] = $layout;

		$params = & $mainframe->getPageParameters('com_wrecruit');
		$id = & $this->get('Id');

		if($layout != 'new_inwrecruit'){
			if (isset($_SESSION['jsuserrole'])) $userrole = $_SESSION['jsuserrole']; else $userrole=null;
			//$config = Array();
			if($curuser != $uid) unset($userrole);
			if(empty($userrole)) $userrole = null;
			if (sizeof($userrole) == 0){
				$userrole =  $model->getUserRole($uid);	
				if (isset($userrole)){ //not empty
					$_SESSION['jsuserrole'] = $userrole;	
				}else{
					if(($needlogin == true) && $layout != 'new_inwrecruit'){//echo '<br> new in wrecruit';
						$mainframe->redirect('index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=new_inwrecruit&Itemid='.$itemid);
					}	
				}
			}
		}	
		
		$themevalue = $config['theme'];
		if ($themevalue != 'templatetheme.css'){
			$theme['title'] = 'jppagetitle';
			$theme['heading'] = 'pageheadline';
			$theme['sectionheading'] = 'sectionheadline';
			$theme['sortlinks'] = 'sortlnks';
			$theme['odd'] = 'odd';
			$theme['even'] = 'even';
		}else{
			$theme['title'] = 'componentheading';
			$theme['heading'] = 'contentheading';
			$theme['sectionheading'] = 'sectiontableheader';
			$theme['sortlinks'] = 'sectiontableheader';
			$theme['odd'] = 'sectiontableentry1';
			$theme['even'] = 'sectiontableentry2';
		}

		// get save filter
		if ($uid != ''){
			if (isset($_SESSION['jsuserfilter']))$userfilter = $_SESSION['jsuserfilter'];else $userfilter=null;
			if (sizeof($userfilter) == 0){
				$result =  $model->getUserFilter($uid);	
				if (isset($result)){ //not empty
					$userfilter[0] = 1;
					$userfilter[1] = $result;
					$_SESSION['jsuserfilter'] = $userfilter;	
					$filterid = $result->id;
				}else{
					$userfilter[0] = 1;
					$_SESSION['jsuserfilter'] = $userfilter;	
				}
			}else{
                            $userfilter= $_SESSION['jsuserfilter'];
                            if(isset($userfilter[1]))$filterid = $userfilter[1]->id;
                        }
		} else $userfilter = '';

		if(isset($userrole->rolefor)) {
			if ($userrole->rolefor == 1) { // employer
				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=controlpanel&Itemid='.$itemid;
				$employerlinks [] = array($link, JText::_('JS_CONTROL_PANEL'),1);
                
				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=formjob&Itemid='.$itemid;
				$employerlinks [] = array($link, JText::_('JS_NEW_JOB'),0);
				
				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=myjobs&Itemid='.$itemid;
				$employerlinks [] = array($link, JText::_('JS_MY_JOBS'),0);

				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=mycompanies&Itemid='.$itemid;
				$employerlinks [] = array($link, JText::_('JS_MY_COMPANIES'),0);

				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=alljobsappliedapplications&Itemid='.$itemid;
				$employerlinks [] = array($link, JText::_('JS_APPLIED_RESUME'),-1);
			}else{

//		if ($cur_user_allow[1] == 1) { // Emp Allow
				if($config['tmenu_jscontrolpanel'] == 1){$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=controlpanel&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_CONTROL_PANEL'),1);
				}
				
				if($config['tmenu_jsjobcategory'] == 1){$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=jobcat&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_JOB_CATEGORIES'),0);
                }
				if($config['tmenu_jssearchjob'] == 1){$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=jobsearch&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_SEARCH_JOB'),0);
                 }
				if($config['tmenu_jsnewestjob'] == 1){$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=listnewestjobs&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_NEWEST_JOBS'),0);
			     }
				if($config['tmenu_jsmyresume'] == 1){$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=myresumes&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_MY_RESUMES'),-1);
				}
			}
		}else{ // user not logined
				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=controlpanel&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_CONTROL_PANEL'),1);

				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=jobcat&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_JOB_CATEGORIES'),0);

				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=jobsearch&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_SEARCH_JOB'),0);

				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=listnewestjobs&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_NEWEST_JOBS'),0);
			
				$link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=myresumes&Itemid='.$itemid;
				$jobseekerlinks [] = array($link, JText::_('JS_MY_RESUMES'),-1);
			}
		
                $page_title = $params->get('page_title');

                if($layout== 'jobcat'){									//job cat
			
                        $page_title .=  ' - ' . JText::_('JS_JOB_CATEGORIES');
			$cmbfiltercountry = $mainframe->getUserStateFromRequest( $option.'cmbfilter_country', 'cmbfilter_country',	'',	'string' );
			$cmbfilterstate = $mainframe->getUserStateFromRequest( $option.'cmbfilter_state', 'cmbfilter_state',	'',	'string' );
			$cmbfiltercounty = $mainframe->getUserStateFromRequest( $option.'cmbfilter_county', 'cmbfilter_county',	'',	'string' );
			$cmbfiltercity = $mainframe->getUserStateFromRequest( $option.'cmbfilter_city', 'cmbfilter_city',	'',	'string' );
			$txtfiltercountry='';
			$txtfilterstate = $mainframe->getUserStateFromRequest( $option.'txtfilter_state', 'txtfilter_state',	'',	'string' );
			$txtfiltercounty = $mainframe->getUserStateFromRequest( $option.'txtfilter_county', 'txtfilter_county',	'',	'string' );
			$txtfiltercity = $mainframe->getUserStateFromRequest( $option.'txtfilter_city', 'txtfilter_city',	'',	'string' );
                        if ($txtfilterstate == 'State') $txtfilterstate = '';
                        if ($txtfiltercounty == 'County') $txtfiltercounty = '';
                        if ($txtfiltercity == 'City') $txtfiltercity = '';

			$filterjobsalaryrange = $mainframe->getUserStateFromRequest( $option.'filter_jobsalaryrange', 'filter_jobsalaryrange',	'',	'string' );
			$filterheighesteducation = $mainframe->getUserStateFromRequest( $option.'filter_heighesteducation', 'filter_heighesteducation',	'',	'string' );
			$filterjobcategory = $mainframe->getUserStateFromRequest( $option.'filter_jobcategory', 'filter_jobcategory',	'',	'string' );
			$filterjobtype = $mainframe->getUserStateFromRequest( $option.'filter_jobtype', 'filter_jobtype',	'',	'string' );

			if (isset($userfilter[1])) {
				if(($cmbfiltercountry == '') && ($cmbfilterstate == '') && ($cmbfiltercounty == '') && ($cmbfiltercity == '') 
					&& ($txtfilterstate == '') && ($txtfiltercounty == '') && ($txtfiltercity == '') 
					&& ($filterjobsalaryrange == '') && ($filterheighesteducation == '') && ($filterjobtype == '')
				){
					$filter = $userfilter[1];
					$cmbfiltercountry = $filter->country;
					if( $filter->state_istext == 1) if($filter->state != '') $txtfilterstate = $filter->state; else $cmbfilterstate = $filter->state;
					if( $filter->county_istext == 1) if($filter->county != '') $txtfiltercounty = $filter->county; else $cmbfiltercounty = $filter->county;
					if( $filter->city_istext == 1) if($filter->city != '') $txtfiltercity = $filter->city; else $cmbfiltercity = $filter->city;

					if($filter->salaryrange != 0) $filterjobsalaryrange = $filter->salaryrange;
					if($filter->heighesteducation != 0) $filterheighesteducation = $filter->heighesteducation;
					if($filterjobtype != 0) $filterjobtype = $filter->jobtype;
//					echo '<br>empty';
				}
//				echo '<br>get user filter';
			}
			$result = $model->getJobCat($cmbfiltercountry,$cmbfilterstate,$cmbfiltercounty,$cmbfiltercity
											,$txtfiltercountry,$txtfilterstate,$txtfiltercounty,$txtfiltercity
											,$filterjobsalaryrange,$filterheighesteducation,$filterjobcategory,$filterjobtype );	


			$application = $result[0];
			$filterlists =  $result[2];
			$filtervalues =  $result[3];
//			$this->assignRef('jobs', $jobs);
			$this->assignRef('filterlists', $filterlists);
			$this->assignRef('filtervalues', $filtervalues);
			$this->assignRef('filterid', $filterid);
		
		}elseif($layout== 'company_jobs'){		
                        if (isset($_GET['sortby']))
				$sort = $_GET['sortby'];
			$sort =  JRequest::getVar('sortby','');
			if (isset($sort)){
				if ($sort == '') 
					{$sort='createddesc';}
			}else
				{$sort='createddesc';}
			$sortby = $this->getJobListOrdering($sort);							
				
			$cmbfiltercountry = $mainframe->getUserStateFromRequest( $option.'cmbfilter_country', 'cmbfilter_country',	'',	'string' );
			$cmbfilterstate = $mainframe->getUserStateFromRequest( $option.'cmbfilter_state', 'cmbfilter_state',	'',	'string' );
			$cmbfiltercounty = $mainframe->getUserStateFromRequest( $option.'cmbfilter_county', 'cmbfilter_county',	'',	'string' );
			$cmbfiltercity = $mainframe->getUserStateFromRequest( $option.'cmbfilter_city', 'cmbfilter_city',	'',	'string' );
			$txtfiltercountry='';
			$txtfilterstate = $mainframe->getUserStateFromRequest( $option.'txtfilter_state', 'txtfilter_state',	'',	'string' );
			$txtfiltercounty = $mainframe->getUserStateFromRequest( $option.'txtfilter_county', 'txtfilter_county',	'',	'string' );
			$txtfiltercity = $mainframe->getUserStateFromRequest( $option.'txtfilter_city', 'txtfilter_city',	'',	'string' );
                        if ($txtfilterstate == 'State') $txtfilterstate = '';
                        if ($txtfiltercounty == 'County') $txtfiltercounty = '';
                        if ($txtfiltercity == 'City') $txtfiltercity = '';

			$filterjobsalaryrange = $mainframe->getUserStateFromRequest( $option.'filter_jobsalaryrange', 'filter_jobsalaryrange',	'',	'string' );
			$filterheighesteducation = $mainframe->getUserStateFromRequest( $option.'filter_heighesteducation', 'filter_heighesteducation',	'',	'string' );
			$filterjobtype = $mainframe->getUserStateFromRequest( $option.'filter_jobtype', 'filter_jobtype',	'',	'string' );
			$filterjobcategory = $mainframe->getUserStateFromRequest( $option.'filter_jobcategory', 'filter_jobcategory',	'',	'string' );

			if (isset($userfilter[1])) {
				if(($cmbfiltercountry == '') && ($cmbfilterstate == '') && ($cmbfiltercounty == '') && ($cmbfiltercity == '') 
					&& ($txtfilterstate == '') && ($txtfiltercounty == '') && ($txtfiltercity == '') 
					&& ($filterjobsalaryrange == '') && ($filterheighesteducation == '') && ($filterjobtype == '')
				){
					$filter = $userfilter[1];
					$cmbfiltercountry = $filter->country;
					if( $filter->state_istext == 1) $txtfilterstate = $filter->state; else $cmbfilterstate = $filter->state;
					if( $filter->county_istext == 1) $txtfiltercounty = $filter->county; else $cmbfiltercounty = $filter->county;
					if( $filter->city_istext == 1) $txtfiltercity = $filter->city; else $cmbfiltercity = $filter->city;

					if($filter->salaryrange != 0) $filterjobsalaryrange = $filter->salaryrange;
					if($filter->heighesteducation != 0) $filterheighesteducation = $filter->heighesteducation;
					if($filter->jobtype != 0) $filterjobtype = $filter->jobtype;
				}
			}
				$companyid =  JRequest::getVar('cd');
				$result =  $model->getActiveJobsByCompany($companyid,$cmbfiltercountry,$cmbfilterstate,$cmbfiltercounty,$cmbfiltercity
											,$txtfiltercountry,$txtfilterstate,$txtfiltercounty,$txtfiltercity
											,$filterjobsalaryrange,$filterheighesteducation,$filterjobcategory,$filterjobtype,$sortby
											 ,$limit,$limitstart);
		
		
		
			$jobs = $result[0];
			
			$filterlists =  $result[2];
			$filtervalues =  $result[3];
			$this->assignRef('listjobconfig',$result[4]);
			$this->assignRef('jobs', $jobs);
			$sortlinks = $this->getJobListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('filterlists', $filterlists);
			$this->assignRef('filtervalues', $filtervalues);
			$this->assignRef('sortlinks', $sortlinks);
			$this->assignRef('companyid', $companyid);
			//$this->assignRef('filterid', $filterid);
                        if (isset($jobs)){
                            $page_title .=  ' - ' . $jobs[0]->companyname.' '.JText::_('JS_JOBS');
                            //if ($mainframe->getCfg('MetaTitle') == '1') $mainframe->addMetaTag('title', $jobs[0]->companyname.' '.JText::_('JS_JOBS'));
                        }
	
		// browse jobs
		}elseif($layout== 'browsejobs'){ 											
			$catid='';
			if (isset($_GET['sortby']))
                            $sort = $_GET['sortby'];
			if (isset($sort)){
                            if ($sort == '') 
                                {$sort='createddesc';}
			}else
                        {
                            $sort='createddesc';
                        }
			$sortby = $this->getJobListOrdering($sort);
			
			$cmbfiltercountry = $mainframe->getUserStateFromRequest( $option.'cmbfilter_country', 'cmbfilter_country',	'',	'string' );
			$cmbfilterstate = $mainframe->getUserStateFromRequest( $option.'cmbfilter_state', 'cmbfilter_state',	'',	'string' );
			$cmbfiltercounty = $mainframe->getUserStateFromRequest( $option.'cmbfilter_county', 'cmbfilter_county',	'',	'string' );
			$cmbfiltercity = $mainframe->getUserStateFromRequest( $option.'cmbfilter_city', 'cmbfilter_city',	'',	'string' );
			$txtfiltercountry='';
			$txtfilterstate = $mainframe->getUserStateFromRequest( $option.'txtfilter_state', 'txtfilter_state',	'',	'string' );
			$txtfiltercounty = $mainframe->getUserStateFromRequest( $option.'txtfilter_county', 'txtfilter_county',	'',	'string' );
			$txtfiltercity = $mainframe->getUserStateFromRequest( $option.'txtfilter_city', 'txtfilter_city',	'',	'string' );
                        if ($txtfilterstate == 'State') $txtfilterstate = '';
                        if ($txtfiltercounty == 'County') $txtfiltercounty = '';
                        if ($txtfiltercity == 'City') $txtfiltercity = '';

			$filterjobsalaryrange = $mainframe->getUserStateFromRequest( $option.'filter_jobsalaryrange', 'filter_jobsalaryrange',	'',	'string' );
			$filterheighesteducation = $mainframe->getUserStateFromRequest( $option.'filter_heighesteducation', 'filter_heighesteducation',	'',	'string' );
			$filterjobtype = $mainframe->getUserStateFromRequest( $option.'filter_jobtype', 'filter_jobtype',	'',	'string' );

			//$filterjobcategory = $mainframe->getUserStateFromRequest(option.'', 'filter_jobcategory',	'',	'string' );
			if (isset($_POST['filter_jobcategory']))$filterjobcategory =$_POST['filter_jobcategory'];else $filterjobcategory='';
			if (isset($userfilter[1])) {
				if(($cmbfiltercountry == '') && ($cmbfilterstate == '') && ($cmbfiltercounty == '') && ($cmbfiltercity == '') 
					&& ($txtfilterstate == '') && ($txtfiltercounty == '') && ($txtfiltercity == '') 
					&& ($filterjobsalaryrange == '') && ($filterheighesteducation == '') && ($filterjobtype == '')
				){
					$filter = $userfilter[1];
					$cmbfiltercountry = $filter->country;
					if( $filter->state_istext == 1) $txtfilterstate = $filter->state; else $cmbfilterstate = $filter->state;
					if( $filter->county_istext == 1) $txtfiltercounty = $filter->county; else $cmbfiltercounty = $filter->county;
					if( $filter->city_istext == 1) $txtfiltercity = $filter->city; else $cmbfiltercity = $filter->city;

					if($filter->salaryrange != 0) $filterjobsalaryrange = $filter->salaryrange;
					if($filter->heighesteducation != 0) $filterheighesteducation = $filter->heighesteducation;
					if($filter->jobtype != 0) $filterjobtype = $filter->jobtype;
				}
			}
			if ($filterjobcategory) $catid = $filterjobcategory;

                        $cat_id =  JRequest::getVar('jobcat');
                        if($cat_id == 'all') $cat_id = '';
                        $country = JRequest::getVar('jobcountry');
                        $jobtype = JRequest::getVar('jobtype');
                        $duration = JRequest::getVar('duration');
                        $jobstatus = JRequest::getVar('jobstatus');
                        $salarystart = JRequest::getVar('salarystart');
                        $salaryend = JRequest::getVar('salaryend');
                        $careerlevel = JRequest::getVar('careerlevel');
                        
                        $result = array();
                        if ($catid == 0 )  $catid = $cat_id;
                        if($catid > 0){
                            $result =  $model->getJobsbyCategory($uid,$catid,$cmbfiltercountry,$cmbfilterstate,$cmbfiltercounty,$cmbfiltercity
							,$txtfiltercountry,$txtfilterstate,$txtfiltercounty,$txtfiltercity
							,$filterjobsalaryrange,$filterheighesteducation,$filterjobcategory,$filterjobtype 
							,$sortby,$limit,$limitstart);
                        }
                        else{
                            $result =  $model->getBrowseJobsList($uid,$country,$jobtype,$duration,$jobstatus,$salarystart
							,$salaryend,$careerlevel,$sortby,$limit,$limitstart);
                        }
			
                        if(!empty($result[0])) $jobs = $result[0];
                        
                        $listcategories = $model->getListCategories();
                        $listcareerlevels = $model->getCareerLevels('');
                        $listjobtypes = $model->getJobType('');
                        $listcountries = $model->getCountries('');
                        //echo '<pre>';print_r($listcareerlevels);exit;
                        
                        $categories = $model->getJobCat('', '', '', '', '', '', '', '', '', '', '', '');	
                        $categories = $categories[0];
                        $locations = $model->getJobCountry();
                        $jobtypes = $model->countJobType();
                        $durations = $model->countJobDuration();
                        $statusjobs = $model->countJobStatus();
                        $salaryranges = $model->countJobSalaryRange();
                        $careerlevels = $model->countJobCareerLevels();
                        if(empty($catid))
                            $catid = 0;
			
			if(!empty($result[2])) $filterlists =  $result[2];
			if(!empty($result[3])) $filtervalues =  $result[3];
			$sortlinks = $this->getJobListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
                        $this->assignRef('categories', $categories);
                        $this->assignRef('locations', $locations);
                        $this->assignRef('jobtypes', $jobtypes);
                        $this->assignRef('durations', $durations);
                        $this->assignRef('statusjobs', $statusjobs);
                        $this->assignRef('salaryranges', $salaryranges);
                        $this->assignRef('careerlevels', $careerlevels);
                        $this->assignRef('listcategories', $listcategories);
                        $this->assignRef('listcareerlevels', $listcareerlevels);
                        $this->assignRef('listjobtypes', $listjobtypes);
                        $this->assignRef('listcountries', $listcountries);
			$this->assignRef('pagination', $pagination);
			$this->assignRef('jobs', $jobs);
			$this->assignRef('category', $result[6]);
			$this->assignRef('filterlists', $filterlists);
			$this->assignRef('filtervalues', $filtervalues);
			$this->assignRef('listjobconfig',$result[4]);
			$this->assignRef('subcategories',$result[5]);
			$this->assignRef('sortlinks', $sortlinks);
			$this->assignRef('categoryid', $catid);
			$this->assignRef('companyid', $companyid);
			$this->assignRef('filterid', $filterid);
			$this->assignRef('cm', JRequest::getVar('cm',''));
                        if (isset($jobs)){
                            $page_title .=  ' - ' . $jobs[0]->cat_title;
                            //if ($mainframe->getCfg('MetaTitle') == '1') $mainframe->addMetaTag('title', $jobs[0]->cat_title);
                        }




		}elseif($layout== 'list_jobs_company'){ 											// list jobs
			if (isset($_GET['sortby']))
				$sort = $_GET['sortby'];
			$sort =  JRequest::getVar('sortby','');
			if (isset($sort)){
				if ($sort == '') 
					{$sort='createddesc';}
			}else
				{$sort='createddesc';}
			$sortby = $this->getJobListOrdering($sort);
			
			$cmbfiltercountry = $mainframe->getUserStateFromRequest( $option.'cmbfilter_country', 'cmbfilter_country',	'',	'string' );
			$cmbfilterstate = $mainframe->getUserStateFromRequest( $option.'cmbfilter_state', 'cmbfilter_state',	'',	'string' );
			$cmbfiltercounty = $mainframe->getUserStateFromRequest( $option.'cmbfilter_county', 'cmbfilter_county',	'',	'string' );
			$cmbfiltercity = $mainframe->getUserStateFromRequest( $option.'cmbfilter_city', 'cmbfilter_city',	'',	'string' );
			$txtfiltercountry='';
			$txtfilterstate = $mainframe->getUserStateFromRequest( $option.'txtfilter_state', 'txtfilter_state',	'',	'string' );
			$txtfiltercounty = $mainframe->getUserStateFromRequest( $option.'txtfilter_county', 'txtfilter_county',	'',	'string' );
			$txtfiltercity = $mainframe->getUserStateFromRequest( $option.'txtfilter_city', 'txtfilter_city',	'',	'string' );
                        if ($txtfilterstate == 'State') $txtfilterstate = '';
                        if ($txtfiltercounty == 'County') $txtfiltercounty = '';
                        if ($txtfiltercity == 'City') $txtfiltercity = '';

			$filterjobsalaryrange = $mainframe->getUserStateFromRequest( $option.'filter_jobsalaryrange', 'filter_jobsalaryrange',	'',	'string' );
			$filterheighesteducation = $mainframe->getUserStateFromRequest( $option.'filter_heighesteducation', 'filter_heighesteducation',	'',	'string' );
			$filterjobtype = $mainframe->getUserStateFromRequest( $option.'filter_jobtype', 'filter_jobtype',	'',	'string' );

			if (isset($_POST['filter_jobcategory']))$filterjobcategory =$_POST['filter_jobcategory'];else $filterjobcategory='';
			if (isset($userfilter[1])) {
				if(($cmbfiltercountry == '') && ($cmbfilterstate == '') && ($cmbfiltercounty == '') && ($cmbfiltercity == '') 
					&& ($txtfilterstate == '') && ($txtfiltercounty == '') && ($txtfiltercity == '') 
					&& ($filterjobsalaryrange == '') && ($filterheighesteducation == '') && ($filterjobtype == '')
				){
					$filter = $userfilter[1];
					$cmbfiltercountry = $filter->country;
					if( $filter->state_istext == 1) $txtfilterstate = $filter->state; else $cmbfilterstate = $filter->state;
					if( $filter->county_istext == 1) $txtfiltercounty = $filter->county; else $cmbfiltercounty = $filter->county;
					if( $filter->city_istext == 1) $txtfiltercity = $filter->city; else $cmbfiltercity = $filter->city;

					if($filter->salaryrange != 0) $filterjobsalaryrange = $filter->salaryrange;
					if($filter->heighesteducation != 0) $filterheighesteducation = $filter->heighesteducation;
					if($filter->jobtype != 0) $filterjobtype = $filter->jobtype;
				}
			}

			$companyid =  JRequest::getVar('jobcom');
			$result =  $model->getActiveJobsByCompany($companyid,$cmbfiltercountry,$cmbfilterstate,$cmbfiltercounty,$cmbfiltercity
											,$txtfiltercountry,$txtfilterstate,$txtfiltercounty,$txtfiltercity
											,$filterjobsalaryrange,$filterheighesteducation,$filterjobcategory,$filterjobtype,$sortby
											 ,$limit,$limitstart);

			$jobs = $result[0];
			
			$filterlists =  $result[2];
			$filtervalues =  $result[3];
			$sortlinks = $this->getJobListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('jobs', $jobs);
			$this->assignRef('listjobconfig',$result[4]);
			$this->assignRef('sortlinks', $sortlinks);
			$this->assignRef('companyid', $companyid);
			$this->assignRef('cm', JRequest::getVar('cm',''));
            if (isset($jobs)){
                $page_title .=  ' - ' . $jobs[0]->companyname;
            }






                        
		}elseif($layout== 'list_subcategoryjobs'){ 											// list jobs
			$catid='';
			if (isset($_GET['sortby']))
				$sort = $_GET['sortby'];
			$sort =  JRequest::getVar('sortby','');
			if (isset($sort)){
				if ($sort == '')
					{$sort='createddesc';}
			}else
				{$sort='createddesc';}
			$sortby = $this->getJobListOrdering($sort);

			$cmbfiltercountry = $mainframe->getUserStateFromRequest( $option.'cmbfilter_country', 'cmbfilter_country',	'',	'string' );
			$cmbfilterstate = $mainframe->getUserStateFromRequest( $option.'cmbfilter_state', 'cmbfilter_state',	'',	'string' );
			$cmbfiltercounty = $mainframe->getUserStateFromRequest( $option.'cmbfilter_county', 'cmbfilter_county',	'',	'string' );
			$cmbfiltercity = $mainframe->getUserStateFromRequest( $option.'cmbfilter_city', 'cmbfilter_city',	'',	'string' );
			$txtfiltercountry='';
			$txtfilterstate = $mainframe->getUserStateFromRequest( $option.'txtfilter_state', 'txtfilter_state',	'',	'string' );
			$txtfiltercounty = $mainframe->getUserStateFromRequest( $option.'txtfilter_county', 'txtfilter_county',	'',	'string' );
			$txtfiltercity = $mainframe->getUserStateFromRequest( $option.'txtfilter_city', 'txtfilter_city',	'',	'string' );
                        if ($txtfilterstate == 'State') $txtfilterstate = '';
                        if ($txtfiltercounty == 'County') $txtfiltercounty = '';
                        if ($txtfiltercity == 'City') $txtfiltercity = '';

			$filterjobsalaryrange = $mainframe->getUserStateFromRequest( $option.'filter_jobsalaryrange', 'filter_jobsalaryrange',	'',	'string' );
			$filterheighesteducation = $mainframe->getUserStateFromRequest( $option.'filter_heighesteducation', 'filter_heighesteducation',	'',	'string' );
			$filterjobtype = $mainframe->getUserStateFromRequest( $option.'filter_jobtype', 'filter_jobtype',	'',	'string' );

			//$filterjobcategory = $mainframe->getUserStateFromRequest(option.'', 'filter_jobcategory',	'',	'string' );
			if (isset($_POST['filter_jobcategory']))$filterjobcategory =$_POST['filter_jobcategory'];else $filterjobcategory='';
			if (isset($userfilter[1])) {
				if(($cmbfiltercountry == '') && ($cmbfilterstate == '') && ($cmbfiltercounty == '') && ($cmbfiltercity == '')
					&& ($txtfilterstate == '') && ($txtfiltercounty == '') && ($txtfiltercity == '')
					&& ($filterjobsalaryrange == '') && ($filterheighesteducation == '') && ($filterjobtype == '')
				){
					$filter = $userfilter[1];
					$cmbfiltercountry = $filter->country;
					if( $filter->state_istext == 1) $txtfilterstate = $filter->state; else $cmbfilterstate = $filter->state;
					if( $filter->county_istext == 1) $txtfiltercounty = $filter->county; else $cmbfiltercounty = $filter->county;
					if( $filter->city_istext == 1) $txtfiltercity = $filter->city; else $cmbfiltercity = $filter->city;

					if($filter->salaryrange != 0) $filterjobsalaryrange = $filter->salaryrange;
					if($filter->heighesteducation != 0) $filterheighesteducation = $filter->heighesteducation;
					if($filter->jobtype != 0) $filterjobtype = $filter->jobtype;
				}
			}
			if ($filterjobcategory) $catid = $filterjobcategory;

                        $cat_id =  JRequest::getVar('jobsubcat');
                        if ($catid == 0 )  $catid = $cat_id;
                        $result =  $model->getJobsbySubCategory($catid,$cmbfiltercountry,$cmbfilterstate,$cmbfiltercounty,$cmbfiltercity
															,$txtfiltercountry,$txtfilterstate,$txtfiltercounty,$txtfiltercity
															,$filterjobsalaryrange,$filterheighesteducation,$filterjobcategory,$filterjobtype
															,$sortby,$limit,$limitstart);


			$jobs = $result[0];

			$filterlists =  $result[2];
			$filtervalues =  $result[3];
			$sortlinks = $this->getJobListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('jobs', $jobs);
			$this->assignRef('totalrecords', $result[1]);
			$this->assignRef('filterlists', $filterlists);
			$this->assignRef('filtervalues', $filtervalues);
			$this->assignRef('listjobconfig',$result[4]);
			$this->assignRef('sortlinks', $sortlinks);
			$this->assignRef('categoryid', $catid);
			$this->assignRef('companyid', $companyid);
			$this->assignRef('jobsubcat', $cat_id);
			$this->assignRef('filterid', $filterid);
			$this->assignRef('cm', JRequest::getVar('cm',''));
                        if (isset($jobs)){
                            $page_title .=  ' - ' . $jobs[0]->cat_title;
                            //if ($mainframe->getCfg('MetaTitle') == '1') $mainframe->addMetaTag('title', $jobs[0]->cat_title);
                        }
		}elseif($layout == 'listnewestjobs'){ 											// list newest job
						
		   $page_title .=  ' - ' . JText::_('JS_NEWEST_JOBS');
			$cmbfiltercountry = $mainframe->getUserStateFromRequest( $option.'cmbfilter_country', 'cmbfilter_country',	'',	'string' );
			//echo '<br>country'.$cmbfiltercountry;die();
			$cmbfilterstate = $mainframe->getUserStateFromRequest( $option.'cmbfilter_state', 'cmbfilter_state',	'',	'string' );
			$cmbfiltercounty = $mainframe->getUserStateFromRequest( $option.'cmbfilter_county', 'cmbfilter_county',	'',	'string' );
			$cmbfiltercity = $mainframe->getUserStateFromRequest( $option.'cmbfilter_city', 'cmbfilter_city',	'',	'string' );
			$txtfiltercountry='';
			$txtfilterstate = $mainframe->getUserStateFromRequest( $option.'txtfilter_state', 'txtfilter_state',	'',	'string' );
			$txtfiltercounty = $mainframe->getUserStateFromRequest( $option.'txtfilter_county', 'txtfilter_county',	'',	'string' );
			$txtfiltercity = $mainframe->getUserStateFromRequest( $option.'txtfilter_city', 'txtfilter_city',	'',	'string' );
                        if ($txtfilterstate == 'State') $txtfilterstate = '';
                        if ($txtfiltercounty == 'County') $txtfiltercounty = '';
                        if ($txtfiltercity == 'City') $txtfiltercity = '';

			$filterjobsalaryrange = $mainframe->getUserStateFromRequest( $option.'filter_jobsalaryrange', 'filter_jobsalaryrange',	'',	'string' );
			$filterheighesteducation = $mainframe->getUserStateFromRequest( $option.'filter_heighesteducation', 'filter_heighesteducation',	'',	'string' );
			$filterjobcategory = $mainframe->getUserStateFromRequest( $option.'filter_jobcategory', 'filter_jobcategory',	'',	'string' );
			$filterjobtype = $mainframe->getUserStateFromRequest( $option.'filter_jobtype', 'filter_jobtype',	'',	'string' );

			if (isset($userfilter[1])) {
				if(($cmbfiltercountry == '') && ($cmbfilterstate == '') && ($cmbfiltercounty == '') && ($cmbfiltercity == '') 
					&& ($txtfilterstate == '') && ($txtfiltercounty == '') && ($txtfiltercity == '') 
					&& ($filterjobsalaryrange == '') && ($filterheighesteducation == '') && ($filterjobtype == '') 
				){
					$filter = $userfilter[1];
					$cmbfiltercountry = $filter->country;
					if( $filter->state_istext == 1) if($filter->state != '') $txtfilterstate = $filter->state; else $cmbfilterstate = $filter->state;
					if( $filter->county_istext == 1) if($filter->county != '') $txtfiltercounty = $filter->county; else $cmbfiltercounty = $filter->county;
					if( $filter->city_istext == 1) if($filter->city != '') $txtfiltercity = $filter->city; else $cmbfiltercity = $filter->city;

					//if($filter->category != 0) $filterjobcategory = $filter->category;
					if($filter->salaryrange != 0) $filterjobsalaryrange = $filter->salaryrange;
					if($filter->heighesteducation != 0) $filterheighesteducation = $filter->heighesteducation;
					if($filterjobtype != 0) $filterjobtype = $filter->jobtype;
				}
			}
			$listtype =  JRequest::getVar('lt'); // for list job by address
			if($listtype == 1){
				$cmbfiltercountry = JRequest::getVar('country','');
				$cmbfilterstate = JRequest::getVar('state','');
				$cmbfiltercounty = JRequest::getVar('county','');
				$cmbfiltercity = JRequest::getVar('city','');
				$txtfilterstate = JRequest::getVar('state','');
				$txtfiltercounty = JRequest::getVar('county','');
				$txtfiltercity = JRequest::getVar('city','');
			}
			$result =  $model->getListNewestJobs($uid, $cmbfiltercountry,$cmbfilterstate,$cmbfiltercounty,$cmbfiltercity
											,$txtfiltercountry,$txtfilterstate,$txtfiltercounty,$txtfiltercity
											,$filterjobsalaryrange,$filterheighesteducation,$filterjobcategory,$filterjobtype
											,$limit,$limitstart);	
			
			$jobs = $result[0];
			$filterlists =  $result[2];
			$filtervalues =  $result[3];
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('listjobconfig',$result[4]);
			$this->assignRef('jobs', $jobs);
			$this->assignRef('filterlists', $filterlists);
			$this->assignRef('filtervalues', $filtervalues);
		}elseif($layout== 'jobsearch'){ 														// job search 
                        $page_title .=  ' - ' . JText::_('JS_SEARCH_JOB');
			$result =  $model->getSearchOptions($uid);	
			$this->assignRef('searchoptions', $result[0]);
			$this->assignRef('searchjobconfig', $result[1]);
			$this->assignRef('canview', $result[2]);
		}elseif($layout== 'jobalertsetting'){											// form company
            $page_title .=  ' - ' . JText::_('JS_JOB_ALERT_INFO');

			$result =  $model->getJobAlertbyUidforForm($uid);
			$this->assignRef('jobsetting', $result[0]);
			$this->assignRef('lists', $result[1]);
			$this->assignRef('cansetjobalert', $result[2]);
			JHTML::_('behavior.formvalidation');
		}elseif($layout== 'job_searchresults'){															// job search results
                        $page_title .=  ' - ' . JText::_('JS_JOB_SEARCH_RESULT');
			if (isset($_GET['sortby']))
				$sort = $_GET['sortby'];
			
			if (isset($sort)){
                            if ($sort == '') 
                                {$sort='createddesc';}
			}else
			{
                            $sort='createddesc';
                        }
                        $sortby = $this->getJobListOrdering($sort);
                        
			if (isset($_POST['isjobsearch'])){
                            if ($_POST['isjobsearch'] == '1'){
                                $_SESSION['isjobsearch'] = '1';
                                unset($_SESSION['filterjob']);
                                
                                $_SESSION['jobsearch_keyword'] = !empty($_POST['keyword']) ? $_POST['keyword'] : '';
                                $_SESSION['jobsearch_jobcategory'] = !empty($_POST['jobcategory']) ? $_POST['jobcategory'] : '';
                                if(is_array($_SESSION['jobsearch_jobcategory'])) $_SESSION['jobsearch_jobcategory'] = implode(',', $_SESSION['jobsearch_jobcategory']);
                                $_SESSION['jobsearch_jobtype'] = !empty($_POST['jobtype']) ? $_POST['jobtype'] : '';
                                $_SESSION['jobsearch_jobstatus'] = !empty($_POST['jobstatus']) ? $_POST['jobstatus'] : '';
                                if(isset($_POST['salaryrangefrom'])) $_SESSION['jobsearch_salaryrangefrom'] = $_POST['salaryrangefrom'];
                                if(isset($_POST['salaryrangeto'])) $_SESSION['jobsearch_salaryrangeto'] = $_POST['salaryrangeto'];
                                if(isset($_POST['salaryrangetype'])) $_SESSION['jobsearch_salaryrangetype'] = $_POST['salaryrangetype'];
                                //if(isset($_POST['educationminimax'])) $_SESSION['jobsearch_educationminimax'] = $_POST['educationminimax'];
                                if(isset($_POST['education'])) $_SESSION['jobsearch_education'] = $_POST['education'];
                                if(isset($_POST['heighestfinisheducation']))$_SESSION['jobsearch_heighestfinisheducation'] = $_POST['heighestfinisheducation'];
                                $_SESSION['jobsearch_shift'] = !empty($_POST['shift']) ? $_POST['shift'] : '';
                                if(isset($_POST['experience']))$_SESSION['jobsearch_experience'] = $_POST['experience'];
                                $_SESSION['jobsearch_durration'] = !empty($_POST['durration']) ? $_POST['durration'] : '';
                                $_SESSION['jobsearch_startpublishing'] = !empty($_POST['startpublishing']) ? $_POST['startpublishing'] : '';
                                $_SESSION['jobsearch_stoppublishing'] = !empty($_POST['stoppublishing']) ? $_POST['stoppublishing'] : '';
                                $_SESSION['jobsearch_company'] = !empty($_POST['company']) ? $_POST['company'] : '';
                                $_SESSION['jobsearch_country'] = isset($_POST['country']) ? $_POST['country'] : '';
                                if(is_array($_SESSION['jobsearch_country'])) $_SESSION['jobsearch_country'] = implode('\',\'', $_SESSION['jobsearch_country']);                                
                                $_SESSION['jobsearch_state'] = isset($_POST['state']) ? $_POST['state'] : '';
                                $_SESSION['jobsearch_county'] = isset($_POST['county']) ? $_POST['county'] : '';
                                $_SESSION['jobsearch_city'] = isset($_POST['city']) ? $_POST['city'] : '';
                                if(isset($_POST['zipcode']))$_SESSION['jobsearch_zipcode'] = $_POST['zipcode'];
                                if(isset($_POST['currency']))$_SESSION['jobsearch_currency'] = $_POST['currency'];
                                $_SESSION['jobsearch_jobcareerlevel'] = !empty($_POST['jobcareerlevel']) ? $_POST['jobcareerlevel'] : '';
                                
                                $_SESSION['jobsearch_lastdate'] = '';
                                if(!empty($_POST['job_posted'])){
                                    $job_post_day = $_POST['job_posted'];
                                    $_SESSION['job_posted'] = $job_post_day;
                                    switch ($job_post_day) {
                                        case 0:
                                            $postday = time();
                                            $_SESSION['jobsearch_lastdate'] = date('Y-m-d 00:00:00', $postday);
                                            break;
                                        case 1:
                                            $postday = time() - 86400;
                                            $_SESSION['jobsearch_lastdate'] = date('Y-m-d H:i:s', $postday);
                                            break;
                                        case 3:
                                            $postday = time() - (86400 * 3);
                                            $_SESSION['jobsearch_lastdate'] = date('Y-m-d H:i:s', $postday);
                                            break;
                                        case 7:
                                            $postday = time() - (86400 * 7);
                                            $_SESSION['jobsearch_lastdate'] = date('Y-m-d H:i:s', $postday);
                                            break;
                                        case 15:
                                            $postday = time() - (86400 * 15);
                                            $_SESSION['jobsearch_lastdate'] = date('Y-m-d H:i:s', $postday);
                                            break;
                                        case 30:
                                            $postday = time() - (86400 * 30);
                                            $_SESSION['jobsearch_lastdate'] = date('Y-m-d H:i:s', $postday);
                                            break;
                                    }
                                }
                            }
			}
                        if(isset($_POST['filterjob'])) {
                            if($_POST['filterjob'] == '1'){
                                $_SESSION['filterjob'] = '1';
                                unset($_SESSION['isjobsearch']);
                                
                                $_SESSION['filter_keyword'] = isset($_POST['keyword']) ? $_POST['keyword'] : '';
                                $_SESSION['filter_curdate'] = '';
                                $_SESSION['filter_lastdate'] = '';
                                if(!empty($_POST['last-day'])){
                                    $last_day = $_POST['last-day'];
                                    $_SESSION['filter_last_day'] = $last_day;
                                    if($last_day == 1){
                                        $lastdate = time() - 86400;
                                        $_SESSION['filter_curdate'] = date('Y-m-d H:i:s');
                                        $_SESSION['filter_lastdate'] = date('Y-m-d H:i:s', $lastdate);
                                    }
                                    else if($last_day == 3){
                                        $lastdate = time() - 259200;
                                        $_SESSION['filter_curdate'] = date('Y-m-d H:i:s');
                                        $_SESSION['filter_lastdate'] = date('Y-m-d H:i:s', $lastdate);
                                    }
                                }
                                
                                $_SESSION['filter_categories'] = isset($_POST['categories']) ? $_POST['categories'] : '';
                                $_SESSION['filter_subcats'] = isset($_POST['subcats']) ? $_POST['subcats'] : '';
                                $_SESSION['filter_careerlevels'] = isset($_POST['careerlevels']) ? $_POST['careerlevels'] : '';
                                $_SESSION['filter_countries'] = isset($_POST['countries']) ? $_POST['countries'] : '';
                                $_SESSION['filter_jobtypes'] = isset($_POST['jobtypes']) ? $_POST['jobtypes'] : '';
                            }
                        }
                        if(!empty($_SESSION['filterjob']) && $_SESSION['filterjob'] == '1'){
                            unset($_SESSION['isjobsearch']);
                            
                            $keyword = !empty($_SESSION['filter_keyword'])?$_SESSION['filter_keyword']:'';
                            $curdate = !empty($_SESSION['filter_curdate'])?$_SESSION['filter_curdate']:'';
                            $lastdate = !empty($_SESSION['filter_lastdate'])?$_SESSION['filter_lastdate']:'';
                            $categories = !empty($_SESSION['filter_categories'])?$_SESSION['filter_categories']:'';
                            $subcats = !empty($_SESSION['filter_subcats'])?$_SESSION['filter_subcats']:'';
                            $careerlevels = !empty($_SESSION['filter_careerlevels'])?$_SESSION['filter_careerlevels']:'';
                            $countries = !empty($_SESSION['filter_countries'])?$_SESSION['filter_countries']:'';
                            $jobtypes = !empty($_SESSION['filter_jobtypes'])?$_SESSION['filter_jobtypes']:'';
                            
                            $result =  $model->getJobFilter($uid, $keyword, $curdate, $lastdate, $categories, $subcats, $careerlevels, $countries, $jobtypes, $sortby, $limit, $limitstart);
                        }
                        else {
                            unset($_SESSION['filterjob']);

                            $keyword = !empty($_SESSION['jobsearch_keyword'])?$_SESSION['jobsearch_keyword']:'';
                            $jobcategory = !empty($_SESSION['jobsearch_jobcategory'])?$_SESSION['jobsearch_jobcategory']:'';
                            $jobtype = !empty($_SESSION['jobsearch_jobtype'])?$_SESSION['jobsearch_jobtype']:'';
                            $jobstatus = !empty($_SESSION['jobsearch_jobstatus'])?$_SESSION['jobsearch_jobstatus']:'';
                            $salaryrangefrom = !empty($_SESSION['jobsearch_salaryrangefrom']) ? $_SESSION['jobsearch_salaryrangefrom'] : '';
                            $salaryrangeto = !empty($_SESSION['jobsearch_salaryrangeto']) ? $_SESSION['jobsearch_salaryrangeto'] : '';
                            $salaryrangetype = !empty($_SESSION['jobsearch_salaryrangetype']) ? $_SESSION['jobsearch_salaryrangetype'] : '';
                            //$educationminimax = $_SESSION['jobsearch_educationminimax'];
                            //$education = $_SESSION['jobsearch_education'];
                            //$education = $_SESSION['jobsearch_heighestfinisheducation'];
                            $shift = !empty($_SESSION['jobsearch_shift'])?$_SESSION['jobsearch_shift']:'';
                            $experience = !empty($_SESSION['jobsearch_experience']) ? $_SESSION['jobsearch_experience'] : '';
                            $durration = !empty($_SESSION['jobsearch_durration'])?$_SESSION['jobsearch_durration']:'';
                            $startpublishing = !empty($_SESSION['jobsearch_startpublishing'])?$_SESSION['jobsearch_startpublishing']:'';
                            $stoppublishing = !empty($_SESSION['jobsearch_stoppublishing'])?$_SESSION['jobsearch_stoppublishing']:'';
                            $company = !empty($_SESSION['jobsearch_company'])?$_SESSION['jobsearch_company']:'';
                            $country = !empty($_SESSION['jobsearch_country'])?$_SESSION['jobsearch_country']:'';
                            $state = !empty($_SESSION['jobsearch_state'])?$_SESSION['jobsearch_state']:'';
                            $county = !empty($_SESSION['jobsearch_county'])?$_SESSION['jobsearch_county']:'';
                            $city = !empty($_SESSION['jobsearch_city'])?$_SESSION['jobsearch_city']:'';
                            $zipcode = !empty($_SESSION['jobsearch_zipcode'])?$_SESSION['jobsearch_zipcode']:'';
                            $currency = !empty($_SESSION['jobsearch_currency']) ? $_SESSION['jobsearch_currency'] : '';
                            $careerlevel = !empty($_SESSION['jobsearch_careerlevel']) ? $_SESSION['jobsearch_careerlevel'] : '';
                            
                            $lastdate = !empty($_SESSION['jobsearch_lastdate']) ? $_SESSION['jobsearch_lastdate'] : '';

                            $result =  $model->getJobSearch($uid,$keyword,$jobcategory,$jobtype,$jobstatus,$currency,$salaryrangefrom,$salaryrangeto,$salaryrangetype
                            ,$shift, $experience, $durration, $startpublishing, $stoppublishing	
                            ,$company,$country,$state,$county,$city,$zipcode,$careerlevel,$sortby,$limit,$limitstart, $lastdate);
                        }
                        
                        $listcategories = $model->getListCategories();
                        $listcareerlevels = $model->getCareerLevels('');
                        $listjobtypes = $model->getJobType('');
                        $listcountries = $model->getCountries('');
                        //echo '<pre>';print_r($listcareerlevels);exit;
                        
                        $categories = $model->getJobCat('', '', '', '', '', '', '', '', '', '', '', '');	
                        $categories = $categories[0];
                        $locations = $model->getJobCountry();
                        $jobtypes = $model->countJobType();
                        $durations = $model->countJobDuration();
                        $statusjobs = $model->countJobStatus();
                        $salaryranges = $model->countJobSalaryRange();
                        $careerlevels = $model->countJobCareerLevels();
                        
                        $options =  $this->get('Options');
			$sortlinks = $this->getJobListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
			$application = $result[0];
			if ( $result[1] <= $limitstart ) $limitstart = 0;
			$pagination = new JPagination($result[1], $limitstart, $limit );
                        $this->assignRef('categories', $categories);
                        $this->assignRef('locations', $locations);
                        $this->assignRef('jobtypes', $jobtypes);
                        $this->assignRef('durations', $durations);
                        $this->assignRef('statusjobs', $statusjobs);
                        $this->assignRef('salaryranges', $salaryranges);
                        $this->assignRef('careerlevels', $careerlevels);
                        $this->assignRef('listcategories', $listcategories);
                        $this->assignRef('listcareerlevels', $listcareerlevels);
                        $this->assignRef('listjobtypes', $listjobtypes);
                        $this->assignRef('listcountries', $listcountries);
			$this->assignRef('application', $application);
			$this->assignRef('pagination', $pagination);
			$this->assignRef('listjobconfig',$result[2]);
			$this->assignRef('searchjobconfig',$result[3]);
			$this->assignRef('canview', $result[4]);
			$this->assignRef('sortlinks', $sortlinks);
		}elseif($layout== 'job_apply'){ 											// job apply
                        $page_title .=  ' - ' . JText::_('JS_APPLYNOW');
			$jobids = JRequest::getVar('bi');
                        $jobresult = array();
                        if($uid){
                            for($i = 0; $i < count($jobids) && $i < 3; $i++) {
                                $job =  $model->getJobbyIdforJobApply($jobids[$i]);
                                $jobresult[] = $job[0];
                            }
                            $result =  $model->getMyResumes($uid);
                        }else{
                            $session = JFactory::getSession();
                            $visitor['visitor'] = 1;
                            $visitor['bi'] = $jobids;
                            $session->set('jsjob_jobapply', $visitor);
                            if ($config['visitor_show_login_message'] != 1){ 
                                $formresumelink = JRoute::_('index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=formresume');
                                 $mainframe->redirect($formresumelink);
                            }

                        }

			$this->assignRef('jobs', $jobresult);
			$this->assignRef('myresumes', $result[0]);
			$this->assignRef('totalresume', $result[1]);
			$this->assignRef('jobcat', JRequest::getVar('jobcat',''));
			$this->assignRef('aj', JRequest::getVar('aj',''));
			$this->assignRef('companyid', JRequest::getVar('cd',''));
		}elseif($layout== 'myappliedjobs'){											//my applied jobs
                        $page_title .=  ' - ' . JText::_('JS_MY_APPLIED_JOBS');
			if (isset($_GET['sortby']))
				$sort = $_GET['sortby'];
			
			$sort =  JRequest::getVar('sortby','');	
			if (isset($sort)){
				if ($sort == '') 
					{$sort='createddesc';}
			}else
				{$sort='createddesc';}
			$sortby = $this->getJobListOrdering($sort);
			$result =  $model->getMyAppliedJobs($uid,$sortby,$limit,$limitstart);	
			$application = $result[0];
			$sortlinks = $this->getJobListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('totalresults', $totalresults);
			$this->assignRef('sortlinks', $sortlinks);
			$this->assignRef('listjobconfig',$result[2]);
		}elseif($layout== 'myresumes'){												// my resumes
                        $page_title .=  ' - ' . JText::_('JS_MY_RESUMES');
			$sort =  JRequest::getVar('sortby','');	
			if (isset($sort)){	if ($sort == '') 	{$sort='createddesc';}
			}else	{$sort='createddesc';}
			$sortby = $this->getResumeListOrdering($sort);
			$result =  $model->getMyResumesbyUid($uid,$sortby,$limit,$limitstart);	
			$this->assignRef('resumes', $result[0]);
			$this->assignRef('resumestyle', $result[2]);
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$sortlinks = $this->getResumeListSorting($sort);
			$sortlinks['sorton'] = $sorton;
			$sortlinks['sortorder'] = $sortorder;
			$this->assignRef('sortlinks', $sortlinks);
		}elseif($layout== 'formresume'){												// form resume
                        $page_title .=  ' - ' . JText::_('JS_RESUME_FORM');
			if (isset($_GET['rd'])) $resumeid = $_GET['rd']; else $resumeid = '';
			$resumeid =  JRequest::getVar('rd','');	
			$result =  $model->getResumebyId($resumeid, $uid);	
			$resumelists =  $this->get('EmpOptions');
                        if(!$uid){
                            $session = JFactory::getSession();
                            $visitor = $session->get('jsjob_jobapply');
                            $this->assignRef('visitor', $visitor);
                        }
			$this->assignRef('resume', $result[0]);
			$this->assignRef('fieldsordering', $result[3]);
			$this->assignRef('canaddnewresume', $result[4]);
			$this->assignRef('packagedetail', $result[5]);
			$this->assignRef('resumelists', $resumelists);
			$this->assignRef('vm', JRequest::getVar('vm',''));
			JHTML::_('behavior.formvalidation');
		}elseif($layout== 'mycoverletters'){												// my cover letters
                        $page_title .=  ' - ' . JText::_('JS_MY_COVER_LETTERS');
			$result =  $model->getMyCoverLettersbyUid($uid,$limit,$limitstart);	
			$this->assignRef('coverletters', $result[0]);
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'view_coverletters'){												// view cover letters
                        $page_title .=  ' - ' . JText::_('JS_VIEW_COVER_LETTERS');
			$userid = $_GET['clu'];
			$userid =  JRequest::getVar('clu','');	
			$result =  $model->getMyCoverLettersbyUid($userid,$limit,$limitstart);	
			$this->assignRef('coverletters', $result[0]);
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
			$this->assignRef('vts', JRequest::getVar('vts',''));
			$this->assignRef('rd', JRequest::getVar('rd',''));
			$this->assignRef('bd', JRequest::getVar('bd',''));
		}elseif($layout== 'my_jobsearches'){												// my job searches
                        $page_title .=  ' - ' . JText::_('JS_JOB_SAVE_SEARCHES');
			$result =  $model->getMyJobSearchesbyUid($uid,$limit,$limitstart);	
			$this->assignRef('jobsearches', $result[0]);
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'viewjobsearch'){												// view job seach
                        $page_title .=  ' - ' . JText::_('JS_VIEW_JOB_SEARCHES');
			$id = $_GET['js'];
			$id =  JRequest::getVar('js','');	
			$search =  $model->getJobSearchebyId($id);	
			if (isset ($search)){
				$_SESSION['jobsearch_keyword'] = $search->jobkeyword;
				if ($search->category != 0) $_SESSION['jobsearch_jobcategory'] = $search->category; else $_SESSION['jobsearch_jobcategory'] = '';
				if ($search->jobtype != 0) $_SESSION['jobsearch_jobtype'] = $search->jobtype; else $_SESSION['jobsearch_jobtype'] = '';
				if ($search->jobstatus != 0) $_SESSION['jobsearch_jobstatus'] = $search->jobstatus; else $_SESSION['jobsearch_jobstatus'] = '';
				if ($search->salaryrange != 0) $_SESSION['jobsearch_jobsalaryrange'] = $search->salaryrange; else $_SESSION['jobsearch_jobsalaryrange'] = '';
				if ($search->heighesteducation != 0) $_SESSION['jobsearch_heighestfinisheducation'] = $search->heighesteducation; else $_SESSION['jobsearch_heighestfinisheducation'] = '';
				if ($search->shift != 0) $_SESSION['jobsearch_shift'] = $search->shift; else $_SESSION['jobsearch_shift'] = '';
				$_SESSION['jobsearch_experience'] = $search->experience;
				$_SESSION['jobsearch_durration'] = $search->durration;
				if ($search->startpublishing != '0000-00-00 00:00:00') $_SESSION['jobsearch_startpublishing'] = $search->startpublishing; else $_SESSION['jobsearch_startpublishing'] = '';
				if ($search->stoppublishing != '0000-00-00 00:00:00') $_SESSION['jobsearch_stoppublishing'] = $search->stoppublishing; else $_SESSION['jobsearch_stoppublishing'] = '';
				if ($search->company != 0) $_SESSION['jobsearch_company'] = $search->company; else $_SESSION['jobsearch_company'] = '';
				$_SESSION['jobsearch_country'] = $search->country;
				$_SESSION['jobsearch_state'] = $search->state;
				$_SESSION['jobsearch_county'] = $search->county;
				$_SESSION['jobsearch_city'] = $search->city;
				$_SESSION['jobsearch_zipcode'] = $search->zipcode;
			
			}
			$mainframe->redirect('index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=job_searchresults&Itemid='.$itemid);
		}elseif($layout== 'formcoverletter'){												// form cover letter
                        $page_title .=  ' - ' . JText::_('JS_COVER_LETTER_FORM');
			if (isset($_GET['cl'])) $letterid = $_GET['cl']; else $letterid = null;
			$letterid =  JRequest::getVar('cl','');	
			$result =  $model->getCoverLetterbyId($letterid, $uid);	
			$this->assignRef('coverletter', $result[0]);
			$this->assignRef('canaddnewcoverletter', $result[4]);
			$this->assignRef('packagedetail', $result[5]);
			JHTML::_('behavior.formvalidation');
		}elseif($layout== 'view_coverletter'){												// view cover letter
                        $page_title .=  ' - ' . JText::_('JS_VIEW_COVER_LETTER');
			$letterid =  JRequest::getVar('cl','');	
			$result =  $model->getCoverLetterbyId($letterid,null);	
			$this->assignRef('coverletter', $result[0]);
			$this->assignRef('vct', JRequest::getVar('vct',''));
		}elseif(($layout== 'view_resume') or ($layout== 'resume_print') ){										// view resume
			if (isset($_GET['id']))
				$empid = $_GET['id'];
			else
				$empid = '';
			if ($empid != ''){
				$application =  $model->getEmpApplicationbyid($empid);	
			}else{
				//$resumeid = $_GET['rd'];
				$resumeid =  JRequest::getVar('rd','');
                                $myresume =  JRequest::getVar('vm','');
                                $jobid = JRequest::getVar('bd','');
                                $folderid = JRequest::getVar('fd','');
                                if ($jobid == '0') $jobid ='';
				$result =  $model->getResumeViewbyId($uid, $jobid, $resumeid,$myresume);

				$this->assignRef('resume', $result[0]);
				$this->assignRef('resume2', $result[1]);
				$this->assignRef('resume3', $result[2]);
				$this->assignRef('fieldsordering', $result[3]);
				$this->assignRef('canview', $result[4]);
				$this->assignRef('vm', JRequest::getVar('vm',''));
				if(!$jobid)$jobid =0;
				$this->assignRef('bd', $jobid);
				$this->assignRef('fd', $folderid);
				$this->assignRef('ms', $myresume);

			}
		}elseif(($layout== 'resume_download') || ($layout== 'resume_view')){	// resume view & download
			$empid = $_GET['rq'];
			$application =  $model->getEmpApplicationbyid($empid);	
		}elseif($layout== 'new_inwrecruit'){												// new in wrecruit
                        $page_title .=  ' - ' . JText::_('JS_WELCOME_WRECRUIT');
			$result =  $model->getUserType($uid);	
			$this->assignRef('usertype', $result[0]);
			$this->assignRef('lists', $result[1]);
		}elseif($layout== 'packages'){												// job seeker package
                        $page_title .=  ' - ' . JText::_('JS_PACKAGES');
			$result =  $model->getJobSeekerPackages($limit,$limitstart);
			$this->assignRef('packages', $result[0]);
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'package_buynow'){
                        $page_title .=  ' - ' . JText::_('JS_BUY_NOW');
			$packageid =  JRequest::getVar('gd');
			$package =$model->getJobSeekerPackageById($packageid);
			$this->assignRef('package', $package);
			$this->assignRef('pb', JRequest::getVar('pb',''));
			
		}elseif($layout== 'package_details'){
                        $page_title .=  ' - ' . JText::_('JS_PACKAGE_DETAILS');
			$packageid =  JRequest::getVar('gd');
			
			$package =$model->getJobSeekerPackageById($packageid);
			$this->assignRef('package', $package);
			
		}elseif($layout== 'purchasehistory'){												// my resume searches
                        //$page_title .=  ' - ' . JText::_('JS_PACKAGES');
			$result =  $model->getJobSeekerPurchaseHistory($uid,$limit,$limitstart);
			$this->assignRef('packages', $result[0]);
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'my_stats'){ 							// my stats
                        $page_title .=  ' - ' . JText::_('JS_MY_STATS');
			$result =  $model->getMyStats_JobSeeker($uid);
			$this->assignRef('resumeallow', $result[0]);
			$this->assignRef('totalresume', $result[1]);
			$this->assignRef('featuredresumeallow', $result[2]);
			$this->assignRef('totalfeaturedresume', $result[3]);
			$this->assignRef('goldresumeallow', $result[4]);
			$this->assignRef('totalgoldresume', $result[5]);
			$this->assignRef('coverlettersallow', $result[6]);
			$this->assignRef('totalcoverletters', $result[7]);
                }elseif($layout== 'jsmessages'){ 							// emp messages
                        $page_title .=  ' - ' . JText::_('JS_MESSAGES');
			$result =  $model->getMessagesbyJobsforJobSeeker($uid,$limit,$limitstart);
			$this->assignRef('messages', $result[0]);
                        if ( $result[1] <= $limitstart ) $limitstart = 0;
                        $pagination = new JPagination($result[1], $limitstart, $limit );
			$this->assignRef('pagination', $pagination);
		}elseif($layout== 'controlpanel'){
			$jscontrolpanel = $model->getConfigByFor('jscontrolpanel');
			$this->assignRef('jscontrolpanel', $jscontrolpanel);
		}elseif($layout== 'jobalertunsubscribe'){
			$email =  JRequest::getVar('email');	
			$this->assignRef('email', $email);
			
		}
		
                $document->setTitle( $page_title);
                //if ($mainframe->getCfg('MetaAuthor') == '1') $mainframe->addMetaTag('author', 'WRecruit 1.6');

		$this->assignRef('application', $application);
		$this->assignRef('config', $config);
		$this->assignRef('theme', $theme);
		$this->assignRef('userrole', $userrole);
//		$option =  $this->get('Option');
		$this->assignRef('option', $option);
		$this->assignRef('params', $params);
		$this->assignRef('viewtype', $viewtype);
		$this->assignRef('jobseekerlinks', $jobseekerlinks);
		$this->assignRef('employerlinks', $employerlinks);
		$this->assignRef('uid', $uid);
		$this->assignRef('id', $id);
		$this->assignRef('Itemid', $itemid);
		$this->assignRef('pdflink', $pdflink);
		$this->assignRef('printlink', $printlink);
		parent :: display($tpl);	
	
		}
	function getJobListSorting( $sort ) {
		$sortlinks['title'] = $this->getSortArg("title",$sort);
		$sortlinks['category'] = $this->getSortArg("category",$sort);
		$sortlinks['jobtype'] = $this->getSortArg("jobtype",$sort);
		$sortlinks['jobstatus'] = $this->getSortArg("jobstatus",$sort);
		$sortlinks['company'] = $this->getSortArg("company",$sort);
		$sortlinks['salaryrange'] = $this->getSortArg("salaryrange",$sort);
		$sortlinks['country'] = $this->getSortArg("country",$sort);
		$sortlinks['created'] = $this->getSortArg("created",$sort);
		$sortlinks['apply_date'] = $this->getSortArg("apply_date",$sort);
		
		return $sortlinks;
	}

	function getEmpListSorting( $sort ) {
		$sortlinks['name'] = $this->getSortArg("name",$sort);
		$sortlinks['category'] = $this->getSortArg("category",$sort);
		$sortlinks['jobtype'] = $this->getSortArg("jobtype",$sort);
		$sortlinks['jobsalaryrange'] = $this->getSortArg("jobsalaryrange",$sort);
		$sortlinks['apply_date'] = $this->getSortArg("apply_date",$sort);
		$sortlinks['email'] = $this->getSortArg("email",$sort);
		
		return $sortlinks;
	}

	function getResumeListSorting( $sort ) {
		$sortlinks['application_title'] = $this->getSortArg("application_title",$sort);
		$sortlinks['jobtype'] = $this->getSortArg("jobtype",$sort);
		$sortlinks['salaryrange'] = $this->getSortArg("salaryrange",$sort);
		$sortlinks['created'] = $this->getSortArg("created",$sort);
		
		return $sortlinks;
	}

	function getJobListOrdering( $sort ) {
		global $sorton, $sortorder;
		switch ( $sort ) {
			case "titledesc": $ordering = "job.title DESC"; $sorton = "title"; $sortorder="DESC"; break;
			case "titleasc": $ordering = "job.title ASC";  $sorton = "title"; $sortorder="ASC"; break;
			case "categorydesc": $ordering = "cat.cat_title DESC"; $sorton = "category"; $sortorder="DESC"; break;
			case "categoryasc": $ordering = "cat.cat_title ASC";  $sorton = "category"; $sortorder="ASC"; break;
			case "jobtypedesc": $ordering = "job.jobtype DESC";  $sorton = "jobtype"; $sortorder="DESC"; break;
			case "jobtypeasc": $ordering = "job.jobtype ASC";  $sorton = "jobtype"; $sortorder="ASC"; break;
			case "jobstatusdesc": $ordering = "job.jobstatus DESC";  $sorton = "jobstatus"; $sortorder="DESC"; break;
			case "jobstatusasc": $ordering = "job.jobstatus ASC";  $sorton = "jobstatus"; $sortorder="ASC"; break;
			case "companydesc": $ordering = "job.company DESC";  $sorton = "company"; $sortorder="DESC"; break;
			case "companyasc": $ordering = "job.company ASC";  $sorton = "company"; $sortorder="ASC"; break;
			case "salaryrangedesc": $ordering = "salary.rangeend DESC";  $sorton = "salaryrange"; $sortorder="DESC"; break;
			case "salaryrangeasc": $ordering = "salary.rangestart ASC";  $sorton = "salaryrange"; $sortorder="ASC"; break;
			case "countrydesc": $ordering = "country.name DESC";  $sorton = "country"; $sortorder="DESC"; break;
			case "countryasc": $ordering = "country.name ASC";  $sorton = "country"; $sortorder="ASC"; break;
			case "createddesc": $ordering = "job.created DESC";  $sorton = "created"; $sortorder="DESC"; break;
			case "createdasc": $ordering = "job.created ASC";  $sorton = "created"; $sortorder="ASC"; break;
			case "apply_datedesc": $ordering = "apply.apply_date DESC";  $sorton = "apply_date"; $sortorder="DESC"; break;
			case "apply_dateasc": $ordering = "apply.apply_date ASC";  $sorton = "apply_date"; $sortorder="ASC"; break;
			default: $ordering = "job.id DESC";
		}
		return $ordering;
	}

	function getResumeListOrdering( $sort ) {
		global $sorton, $sortorder;
		switch ( $sort ) {
			case "application_titledesc": $ordering = "resume.application_title DESC"; $sorton = "application_title"; $sortorder="DESC"; break;
			case "application_titleasc": $ordering = "resume.application_title ASC";  $sorton = "application_title"; $sortorder="ASC"; break;
			case "jobtypedesc": $ordering = "resume.jobtype DESC";  $sorton = "jobtype"; $sortorder="DESC"; break;
			case "jobtypeasc": $ordering = "resume.jobtype ASC";  $sorton = "jobtype"; $sortorder="ASC"; break;
			case "salaryrangedesc": $ordering = "salary.rangeend DESC";  $sorton = "salaryrange"; $sortorder="DESC"; break;
			case "salaryrangeasc": $ordering = "salary.rangestart ASC";  $sorton = "salaryrange"; $sortorder="ASC"; break;
			case "createddesc": $ordering = "resume.create_date DESC";  $sorton = "created"; $sortorder="DESC"; break;
			case "createdasc": $ordering = "resume.create_date ASC";  $sorton = "created"; $sortorder="ASC"; break;
			default: $ordering = "resume.id DESC";
		}
		return $ordering;
	}

	function getEmpListOrdering( $sort ) {
		global $sorton, $sortorder;
		switch ( $sort ) {
			case "namedesc": $ordering = "app.first_name DESC"; $sorton = "name"; $sortorder="DESC"; break;
			case "nameasc": $ordering = "app.first_name ASC";  $sorton = "name"; $sortorder="ASC"; break;
			case "categorydesc": $ordering = "cat.cat_title DESC"; $sorton = "category"; $sortorder="DESC"; break;
			case "categoryasc": $ordering = "cat.cat_title ASC";  $sorton = "category"; $sortorder="ASC"; break;
			case "jobtypedesc": $ordering = "app.jobtype DESC";  $sorton = "jobtype"; $sortorder="DESC"; break;
			case "jobtypeasc": $ordering = "app.jobtype ASC";  $sorton = "jobtype"; $sortorder="ASC"; break;
			case "jobsalaryrangedesc": $ordering = "salary.rangestart DESC";  $sorton = "jobsalaryrange"; $sortorder="DESC"; break;
			case "jobsalaryrangeasc": $ordering = "salary.rangestart ASC";  $sorton = "jobsalaryrange"; $sortorder="ASC"; break;
			case "apply_datedesc": $ordering = "apply.apply_date DESC";  $sorton = "apply_date"; $sortorder="DESC"; break;
			case "apply_dateasc": $ordering = "apply.apply_date ASC";  $sorton = "apply_date"; $sortorder="ASC"; break;
			case "emaildesc": $ordering = "app.email_address DESC";  $sorton = "email"; $sortorder="DESC"; break;
			case "emailasc": $ordering = "app.email_address ASC";  $sorton = "email"; $sortorder="ASC"; break;
			default: $ordering = "job.id DESC";
		}
		return $ordering;
	}

	function getSortArg( $type, $sort ) {
		$mat = array();
		if ( preg_match( "/(\w+)(asc|desc)/i", $sort, $mat ) ) {
			if ( $type == $mat[1] ) {
				return ( $mat[2] == "asc" ) ? "{$type}desc" : "{$type}asc";
			} else {
				return $type . $mat[2];
			}
		}
		return "iddesc";
	}


}
?>
